#include "watched-mountpoint.hpp"

mounts::WatchedMountPoint::WatchedMountPoint(std::string filename)
{
	/*
	 * Open the pidfile in /var/run/distrefine and read it into a string
	 */
	std::ifstream fs(filename.c_str());
	getline(fs, watched_mount_point);
	fs.close();
	
	/*
	 * Extract the part after the delimiter (the ":")
	 */
	int val= watched_mount_point.find(':');
	watched_mount_point= watched_mount_point.substr(val+1, std::string::npos);
	
	/*
	 * Trim off the end '/' if it exists IF "/" isn't the only character in the
	 * path because a user could input /my/path/ instead of /my/path.
	 */
	if ((watched_mount_point.at(watched_mount_point.length()-1) == '/') && (watched_mount_point != "/"))
	{
		watched_mount_point.erase(watched_mount_point.length()-1);
	}
}